#include"ContactException.h"
#include"ContactsServer.h"
#include<iostream>
using namespace std;
void menu()
{
    cout<<"--------------------------------------------"<<endl;
    cout<<"----------------请选择操作-------------------"<<endl;
    cout<<"----------------1.ADD-----------------------"<<endl;
    cout<<"----------------2.DEL-----------------------"<<endl;
    cout<<"----------------3.FIND_ALL------------------"<<endl;
    cout<<"----------------4.FIND_ONE------------------"<<endl;
    cout<<"----------------0.EXIT----------------------"<<endl;
    cout<<"--------------------------------------------"<<endl;

}
int main()
{
    enum OPTION{
        ADD=1,
        DEL,
        FIND_ALL,
        FIND_ONE

    };
    ContactsServer contactsServer;
    int option=0;
    do
    {
        /* code */
        menu();
        cout<<"请输入选项：";
        cin>>option;
        cin.ignore(256,'\n');
        try{
            switch (option)
            {
            case OPTION::ADD:
                contactsServer.addContact();
                break;
            case OPTION::DEL:
                contactsServer.delContact();
                break;
            case OPTION::FIND_ALL:
                contactsServer.findContacts();
                break;
            case OPTION::FIND_ONE:
                contactsServer.findOneContact();
                break;
            case 0:
                cout<<"程序退出！！！"<<endl;
                return 0;
            default:
                cout<<"选项错误！！！"<<endl;
                break;
            }
        }catch(const ContactExpection& e)
        {
            cerr<<"--->操作通信录时发生异常！！！"<<endl;
            cerr<<"--->异常信息："<<e.what()<<endl;
        }
        catch(const std::exception& e)
        {
            cerr<<"--->操作通信录时发生异常！！！"<<endl;
            cerr<<"--->异常信息："<<e.what()<<endl;
        }
        catch(...)
        {
            cerr<<"未知错误！！！"<<endl;
        }
    } while (option);
    

    return 0;
}
